package com.ifox.entity;

import java.util.ArrayList;
import java.util.List;

import com.ifox.common.ConnectTypes;
import com.ifox.common.Constant;

public class IFox {
	
	public static final int SRC = 0;
	public static final int TARGET = 1;
	
	private String ifoxName;//接口名称
	private int sleepTime = 10;//抓取间隔(单位:秒)
	private int fetchCount = 100;//抓取数量(100条)
	//源数据库
	private String srcIp;
	private String srcPort;
	private String srcDb;
	private String srcConnType = "SQLServer2008";
	private String srcUsername;
	private String srcCharset;
	private String srcPassword;
	private String srcShowname = "源数据库";
	private String srcTestSql;
	//目标数据库
	private String targetIp;
	private String targetPort;
	private String targetDb;
	private String targetConnType = "SQLServer2008";
	private String targetUsername;
	private String targetCharset;
	private String targetPassword;
	private String targetShowname = "目标数据库";
	private String targetTestSql;
	
	private List<IFoxTable> tables = new ArrayList<IFoxTable>();
	
	public void removeTable(String srcTable,String targetTable){
		for(IFoxTable table : tables){
			if(table.getSrcTable().equals(srcTable) && table.getTargetTable().equals(targetTable)){
				tables.remove(table);
				break;
			}
		}
	}
	
	public IFoxTable getTable(String srcTable,String targetTable){
		IFoxTable tb = null;
		for(IFoxTable table : tables){
			if(table.getSrcTable().equals(srcTable) && table.getTargetTable().equals(targetTable)){
				tb = table;
				break;
			}
		}
		return tb;
	}
	
	public String getConnStr(int type){
		String ip = "";
		String port = "";
		String db = "";
		String connType = "";
		String url = "";
		if(type==SRC){
			ip = srcIp;
			port = srcPort;
			db = srcDb;
			connType = srcConnType;
		}else if(type==TARGET){
			ip = targetIp;
			port = targetPort;
			db = targetDb;
			connType = targetConnType;
		}else{
			return "";
		}
		switch(ConnectTypes.valueOf(connType)){
		case SQLServer2008:
			url = "jdbc:jtds:sqlserver://"+ip+":"+port+";DatabaseName="+db+";SelectMethod=cursor;UserCursor=";
			break;
		case Oracle10g:
			url = "jdbc:oracle:thin:@"+ip+":"+port+":"+db;
			break;
		}
		return url;
	}
	
	public String getDriverClass(String connectType){
		String driver = "";
		switch(ConnectTypes.valueOf(connectType)){
		case SQLServer2008:
			driver = Constant.JTDS_DRIVER;
			break;
		case Oracle10g:
			driver = Constant.ORACLE10G_DRIVER;
			break;
		}
		return driver;
	}
	
	//getter/setter＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
	public String getIfoxName() {
		return ifoxName;
	}
	public void setIfoxName(String ifoxName) {
		this.ifoxName = ifoxName;
	}
	public int getSleepTime() {
		return sleepTime;
	}
	public void setSleepTime(int sleepTime) {
		this.sleepTime = sleepTime;
	}
	public String getSrcIp() {
		return srcIp;
	}
	public void setSrcIp(String srcIp) {
		this.srcIp = srcIp;
	}
	public String getSrcPort() {
		return srcPort;
	}
	public void setSrcPort(String srcPort) {
		this.srcPort = srcPort;
	}
	public String getSrcDb() {
		return srcDb;
	}
	public void setSrcDb(String srcDb) {
		this.srcDb = srcDb;
	}
	public String getSrcConnType() {
		return srcConnType;
	}
	public void setSrcConnType(String srcConnType) {
		this.srcConnType = srcConnType;
	}
	public String getSrcUsername() {
		return srcUsername;
	}
	public void setSrcUsername(String srcUsername) {
		this.srcUsername = srcUsername;
	}
	public String getSrcCharset() {
		return srcCharset;
	}
	public void setSrcCharset(String srcCharset) {
		this.srcCharset = srcCharset;
	}
	public String getSrcPassword() {
		return srcPassword;
	}
	public void setSrcPassword(String srcPassword) {
		this.srcPassword = srcPassword;
	}
	public String getSrcShowname() {
		return srcShowname;
	}
	public void setSrcShowname(String srcShowname) {
		this.srcShowname = srcShowname;
	}
	public String getTargetIp() {
		return targetIp;
	}
	public void setTargetIp(String targetIp) {
		this.targetIp = targetIp;
	}
	public String getTargetPort() {
		return targetPort;
	}
	public void setTargetPort(String targetPort) {
		this.targetPort = targetPort;
	}
	public String getTargetDb() {
		return targetDb;
	}
	public void setTargetDb(String targetDb) {
		this.targetDb = targetDb;
	}
	public String getTargetConnType() {
		return targetConnType;
	}
	public void setTargetConnType(String targetConnType) {
		this.targetConnType = targetConnType;
	}
	public String getTargetUsername() {
		return targetUsername;
	}
	public void setTargetUsername(String targetUsername) {
		this.targetUsername = targetUsername;
	}
	public String getTargetCharset() {
		return targetCharset;
	}
	public void setTargetCharset(String targetCharset) {
		this.targetCharset = targetCharset;
	}
	public String getTargetPassword() {
		return targetPassword;
	}
	public void setTargetPassword(String targetPassword) {
		this.targetPassword = targetPassword;
	}
	public String getTargetShowname() {
		return targetShowname;
	}
	public void setTargetShowname(String targetShowname) {
		this.targetShowname = targetShowname;
	}
	public List<IFoxTable> getTables() {
		return tables;
	}
	public void setTables(List<IFoxTable> tables) {
		this.tables = tables;
	}
	public int getFetchCount() {
		return fetchCount;
	}
	public void setFetchCount(int fetchCount) {
		this.fetchCount = fetchCount;
	}

	public String getSrcTestSql() {
		return srcTestSql;
	}

	public void setSrcTestSql(String srcTestSql) {
		this.srcTestSql = srcTestSql;
	}

	public String getTargetTestSql() {
		return targetTestSql;
	}

	public void setTargetTestSql(String targetTestSql) {
		this.targetTestSql = targetTestSql;
	}
}
